package per.dg.sqlite.room;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import per.dg.sqlite.Constant;
import per.dg.sqlite.room.dao.UserDao;
import per.dg.sqlite.room.entity.User;

@Database(entities = {User.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {

    private static AppDatabase sInstance;

    public static AppDatabase getInstance(final Context mContext) {
        if (sInstance == null) {
            synchronized (AppDatabase.class) {
                if (sInstance == null) {
                    sInstance = Room.databaseBuilder(mContext.getApplicationContext(),
                            AppDatabase.class, Constant.SQLITE_NAME).build();
                }
            }
        }
        return sInstance;
    }

    public abstract UserDao userDao();

}
